@echo off

(
	@set /p aES_SEL=
)< MILB_SDK_CHIP_ES.ini

(
	@set /p aSDRAM_SEL=
)< MILB_SDK_MEM_SIZE.ini

(
	@set /p aBOARD=
	@set /p aETHER=
	@set /p aEMMCBOOT=
	@set /p aSENSOR=
	@set /p aGYRO=
	@set /p aEIS_X=
	@set /p aEIS_Y=
	@set /p aEIS_Z=
	@set /p aRESOURCE_FOLDER=
	@set /p aRTOS_CPU_NUM=
	
)< MILB_SDK_CONFIG.ini

if "%aSDRAM_SEL%"=="sdram_1GB" (
  SET aSDRAM_SIZE=1
) else (
  SET aSDRAM_SIZE=2
)

if "%aRTOS_CPU_NUM%"=="3" (
  SET aLINUX_SUFFIX=
) else (
  SET aLINUX_SUFFIX=_2core
)

if not exist "..\CM0_RTOS\Project\bin\RS_MILBCM0.bin" (
	echo "NOT FOUND ..\CM0_RTOS\Project\bin\RS_MILBCM0.bin"
	goto FILE_ERROR
)
if not exist "..\CA7_Boot_Strap\project\bin\Boot_strap.bin" (
	echo "NOT FOUND ..\CA7_Boot_Strap\project\bin\Boot_strap.bin"
	goto FILE_ERROR
)
if not exist "..\CA7_RTOS\target\cpu_tkernel\project\bin\MILB_SDK.bin" (
	echo "NOT FOUND ..\CA7_RTOS\target\cpu_tkernel\project\bin\MILB_SDK.bin"
	goto FILE_ERROR
)
if not exist "..\CA7_RTOS_Resource\RESOURCE.bin" (
	echo "NOT FOUND ..\CA7_RTOS_Resource\RESOURCE.bin"
	goto FILE_ERROR
)
if not exist "..\CA7_RTOS_Userdata\User_data.bin" (
	echo "NOT FOUND ..\CA7_RTOS_Userdata\User_data.bin"
	goto FILE_ERROR
)

@echo on
copy ..\CM0_RTOS\Project\bin\RS_MILBCM0.bin .\
copy ..\CA7_Boot_Strap\project\bin\Boot_strap.bin .\
copy ..\CA7_RTOS\target\cpu_tkernel\project\bin\MILB_SDK.bin .\
copy ..\CA7_Linux\%aSDRAM_SIZE%GB\LINUX%aLINUX_SUFFIX%.bin .\LINUX.bin
copy ..\CA7_Linux\%aSDRAM_SIZE%GB\initramfs%aLINUX_SUFFIX% .\initramfs
copy ..\CA7_RTOS_Resource\RESOURCE.bin .\
copy ..\CA7_RTOS_Userdata\User_data.bin .\
@echo off

AddHeader.exe 3 0 RS_MILBCM0.bin
AddHeader.exe 4 0 Boot_strap.bin
AddHeader.exe 4 2 MILB_SDK.bin
AddHeader.exe 4 5 LINUX.bin
AddHeader.exe 4 6 initramfs
AddHeader.exe 4 8 RESOURCE.bin
AddHeader.exe 4 9 User_data.bin

if exist "warp.bin" (
	AddHeader.exe 4 7 warp.bin
	@copy wk\RS_MILBCM0.bin_addhead/B + wk\Boot_strap.bin_addhead/B + wk\MILB_SDK.bin_addhead/B + wk\LINUX.bin_addhead/B + wk\initramfs_addhead/B + wk\warp.bin_addhead/B + wk\RESOURCE.bin_addhead/B + wk\User_data.bin_addhead/B DATA.bin/B
) else (
	@copy wk\RS_MILBCM0.bin_addhead/B + wk\Boot_strap.bin_addhead/B + wk\MILB_SDK.bin_addhead/B + wk\LINUX.bin_addhead/B + wk\initramfs_addhead/B + wk\RESOURCE.bin_addhead/B + wk\User_data.bin_addhead/B DATA.bin/B
)

del RS_MILBCM0.bin
del Boot_strap.bin
del MILB_SDK.bin
del LINUX.bin
del initramfs
del RESOURCE.bin
del User_data.bin


@echo %0
@echo complete !

:EXIT
endlocal
exit /b

:FILE_ERROR
if exist "DATA.bin" (
	del DATA.bin
)
